package com.example.controller;

import com.example.constant.ServicePrefixConstant;
import com.example.dto.Oauth2RegisteredClientDTO;
import com.example.feign.AuthFeignClient;
import com.example.feign.RegisteredClientFeignClient;
import com.example.model.api.Result;
import com.example.model.api.ResultBuilder;
import com.example.security.RegisteredClientServiceImpl;
import io.swagger.v3.oas.annotations.Hidden;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.security.core.Authentication;
import org.springframework.security.oauth2.server.authorization.client.RegisteredClient;
import org.springframework.web.bind.annotation.*;
import reactor.core.publisher.Mono;

@RestController
@Tag(name = "注册客户端")
@RequestMapping("/registerclient")
public class RegisteredClientController implements RegisteredClientFeignClient {
    @Autowired
    private RegisteredClientServiceImpl registeredClientService;

    @PostMapping("/save") // registerclient/save
    public Result<Oauth2RegisteredClientDTO> saveRegisteredClient(@RequestBody Oauth2RegisteredClientDTO dto) {
        Oauth2RegisteredClientDTO oauth2RegisteredClientDTO = registeredClientService.saveRegisteredClient(dto);
        return new Result<Oauth2RegisteredClientDTO>().ok(oauth2RegisteredClientDTO);
    }
    @GetMapping("{id}")
    public Result<Oauth2RegisteredClientDTO> get(@PathVariable("id") String id) {
        Oauth2RegisteredClientDTO registeredClient = registeredClientService.get(id);
        return new Result<Oauth2RegisteredClientDTO>().ok(registeredClient);
    }

}
